var num=0;
var ox=350;
var oy=340;
var aa1,aa2,aa3,aa4,aa5,bb1,bb2,bb3,bb4,bb5;


var x1=new array();
var y1=new array();
var x2=new array();
var y2=new array();

var tempmaxx,tempminx,tempmaxy,tempminy;

function initialize() {	
   _root.createEmptyMovieClip ("mymc", 2);//建立绘图对象
   a0="";a1="";a2="";a3="";
   //a4="";a5="";
   b0="";b1="";b2="";b3="";
   tao="";aph="";
   sk1="";
   sk2="";
   sk3="";
   
   //b4="";b5="";
   ph0="";ph1="";ph2="";ph3="";
   amp0="";amp1="";amp2="";amp3="";
   xxx=0;
 }
function initialize1() {	
   _root.createEmptyMovieClip ("mymc", 2);//建立绘图对象
   sk1="";
   sk2="";
   sk3="";
   xxx=0;
 }
function getdata(){
	num=0;
	w=0.1;
	tmpx=1;tmpy=1;
	while (w<=2000) {
	tht1 = bb0-bb2*w*w;
	tht2 = bb1*w-bb3*w*w*w;
	tht3 = aa0-aa2*w*w;
	tht4 = aa1*w-aa3*w*w*w;
	xx = (tht1*tht3+tht2*tht4)/(tht3*tht3+tht4*tht4);
	yy = (tht2*tht3-tht1*tht4)/(tht3*tht3+tht4*tht4);
	lwa = math.sqrt(xx*xx+yy*yy);
	x1[num] = 20*((math.log(lwa))/(math.log(10)));
	wa = ((math.log(10*w))/(math.log(10)));
	
	
	if (xx == 0) {
		if (yy>=0) {
			fai = 90;
		            } else {
			               fai = -90;
		                              }
	} else if (xx<0) {
		if (yy>0){if((num>0)&&(y1[num-1]<=0))
		        {fai = -180+math.atan(yy/xx)*180/Math.PI;}//
		       else{	fai = 180+math.atan(yy/xx)*180/Math.PI;
		         }//
		}
			
		if (yy<0){
			if((num>0)&&(y1[num-1]>=0))
		        {fai = 180+math.atan(yy/xx)*180/Math.PI;}//
		       else{	
		         fai = -180+math.atan(yy/xx)*180/Math.PI;}
				 //
		}
	    if(yy==0){fai=-180;}} else {
		{fai = math.atan(yy/xx)*180/Math.PI;}
	}
	
	y1[num]=fai;
	tmpx=xx;tmpy=yy;
	w=w*Math.pow(10,0.01);
	num=num+1;
	}
	
	////
	num=0;
	w=0.1;
	tmpx=1;tmpy=1;
	while (w<=2000) {
	tht1 = bbb0-bbb2*w*w;
	tht2 = bbb1*w-bbb3*w*w*w;
	tht3 = aaa0-aaa2*w*w;
	tht4 = aaa1*w-aaa3*w*w*w;
	xx = (tht1*tht3+tht2*tht4)/(tht3*tht3+tht4*tht4);
	yy = (tht2*tht3-tht1*tht4)/(tht3*tht3+tht4*tht4);
	lwa = math.sqrt(xx*xx+yy*yy);
	x2[num] = 20*((math.log(lwa))/(math.log(10)));
	wa = ((math.log(10*w))/(math.log(10)));
	
	
	if (xx == 0) {
		if (yy>=0) {
			fai = 90;
		            } else {
			               fai = -90;
		                              }
	} else if (xx<0) {
		if (yy>0){if((num>0)&&(y2[num-1]<=0))
		        {fai = -180+math.atan(yy/xx)*180/Math.PI;}//
		       else{	fai = 180+math.atan(yy/xx)*180/Math.PI;
		         }//
		}
			
		if (yy<0){
			if((num>0)&&(y2[num-1]>=0))
		        {fai = 180+math.atan(yy/xx)*180/Math.PI;}//
		       else{	
		         fai = -180+math.atan(yy/xx)*180/Math.PI;}
				 //
		}
	    if(yy==0){fai=-180;}} else {
		{fai = math.atan(yy/xx)*180/Math.PI;}
	}
	
	y2[num]=fai;
	tmpx=xx;tmpy=yy;
	w=w*Math.pow(10,0.01);
	num=num+1;
	}
	/////
}


function getmax_xy(){
	tempmaxx=Math.abs(x[0]);tempminx=Math.abs(x[0]);
	tempmaxy=Math.abs(y[0]);tempminy=Math.abs(y[0]);
	for (j=1;j<num;j=j+1)
	   {  if (tempmaxx<Math.abs(x1[j])){tempmaxx=Math.abs(x1[j])};if (tempminx>Math.abs(x1[j])){temptminx=Math.abs(x1[j])};
		  if (tempmaxy<Math.abs(y1[j])){tempmaxy=Math.abs(y1[j])};if (tempminy>Math.abs(y1[j])){temptminy=Math.abs(y1[j])};
	   }
	   for (j=1;j<num;j=j+1)
	   {  if (tempmaxx<Math.abs(x2[j])){tempmaxx=Math.abs(x2[j])};if (tempminx>Math.abs(x2[j])){temptminx=Math.abs(x2[j])};
		  if (tempmaxy<Math.abs(y2[j])){tempmaxy=Math.abs(y2[j])};if (tempminy>Math.abs(y2[j])){temptminy=Math.abs(y2[j])};
	   }
	   for (j=1;j<num;j=j+1)
	   {  if (tempmaxx<Math.abs(x1[j]+x2[j])){tempmaxx=Math.abs(x1[j]+x2[j])};if (tempminx>Math.abs(x1[j]+x2[j])){temptminx=Math.abs(x1[j]+x2[j])};
		  if (tempmaxy<Math.abs(y1[j]+y2[j])){tempmaxy=Math.abs(y1[j]+y2[j])};if (tempminy>Math.abs(y1[j]+y2[j])){temptminy=Math.abs(y1[j]+y2[j])};
	   }
	   tempmaxx=(Math.floor(tempmaxx/20)+1)*20;tempmaxy=Math.round(tempmaxy);
}

function drawaxis(){
	if (tempmaxx==0) {tempmaxx=1;}
	if (tempmaxy==0) {tempmaxy=1;}
	dx=130/(1.0*tempmaxx);
	dy=130/(1.0*tempmaxy);
	amp3=-tempmaxx;amp2=amp3/2;amp1=-amp2;amp0=tempmaxx;
	ph3=-tempmaxy;ph2=ph3/2;ph1=-ph2;ph0=tempmaxy;
}

function drawLine(i) {
	clr=new array(0xffff00,0xff00,0xffff,0xff00ff);
    with(_root.mymc) {
		linestyle(2, clr[1], 100);
		moveTo(105+0*220/400,340-dx*x1[0]);
		for(j=0;j<num;j++) {
			lineTo(105+j*220/400,340-dx*x1[j]);}
			moveTo(430+0*220/400,340-dy*y1[0]);
		for(j=0;j<num;j++) {
			lineTo(430+j*220/400,340-dy*y1[j]);}
		moveTo(630,178);lineTo(640,178);
			sk1="Gk";
			sk2="Gc";
			sk3="Gk'";
			

        
		linestyle(1, clr[2], 100);
		moveTo(105+0*220/400,340-dx*x2[0]);
		for(j=0;j<num;j++) {
			lineTo(105+j*220/400,340-dx*x2[j]);}
			moveTo(430+0*220/400,340-dy*y2[0]);
		for(j=0;j<num;j++) {
			lineTo(430+j*220/400,340-dy*y2[j]);}
			moveTo(630,208);lineTo(640,208);
		
		linestyle(2, clr[3], 100);
		moveTo(105+0*220/400,340-dx*(x1[0]+x2[0]));
		for(j=0;j<num;j++) {
			lineTo(105+j*220/400,340-dx*(x1[j]+x2[j]));}
			moveTo(430+0*220/400,340-dy*(y1[0]+y2[0]));
		for(j=0;j<num;j++) {
			lineTo(430+j*220/400,340-dy*(y1[j]+y2[j]));}
			moveTo(630,238);lineTo(640,238);
	}
};



initialize();

//////

//////////


BTNInput2.onRelease = function() {
 		if (a0 eq "") {	aa0 = 0;} else {aa0 = a0;}
		if (a1 eq "") {	aa1 = 0;} else {aa1 = a1;}
		if (a2 eq "") {	aa2 = 0;} else {aa2 = a2;}
		if (a3 eq "") {aa3 = 0;	} else {aa3 = a3;}
		if (a4 eq "") {	aa4 = 0;} else {aa4 = a4;}
		if (a5 eq "") {aa5 = 0;	} else {aa5 = a5;}
		if (b0 eq "") {	bb0 = 0;} else {bb0 = b0;}
		if (b1 eq "") {	bb1 = 0;} else {bb1 = b1;}
		if (b2 eq "") {	bb2 = 0;} else {bb2 = b2;}
		if (b3 eq "") {	bb3 = 0;} else {bb3 = b3;}
		if (b4 eq "") {	bb4 = 0;} else {bb4 = b4;}
		if (b5 eq "") {	bb5 = 0;} else {bb5 = b5;}
		if (tao eq "") {tao = "1";tao1=1;} else{tao1=tao;}
		if (aph eq "") {aph = 0.2;aph1=0.2;} else{aph1=aph;}
		if ((aph1>=1)||(aph1<=0)) {aph=0.2;aph1=0.2;};
		
		bbb0=1;bbb1=tao1;bbb2=0;
		aaa0=1;aaa1=aph1*tao1;aaa2=0;
		
		
		
		if (xxx==0){
		if(Math.abs (aa0)+Math.abs (aa1)+Math.abs (aa2)+Math.abs (aa3)+Math.abs (aa4)+Math.abs (aa5)!=0){
		getdata();
		getmax_xy();
		drawaxis();
		drawLine(1);xxx=1;err1=""}
		else{err1="Error!"}
		}
  }

BTNInput3.onRelease = function() {
	
	initialize1();
	err1=""
	xxx=0;
}
